﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.ServiceHosting.ServiceRuntime;

namespace Dtyo_WebRole.Emp
{
    public partial class EmpList : System.Web.UI.Page
    {
        private DtyoDataSource ds;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                EmpTimer.Enabled = true;
            }
        }

        protected void SaveEmployeeButton_Click(object sender, EventArgs e)
        {
            RoleManager.WriteToLog("Information", string.Format("Creating new employee"));

            Employee newEntry = new Employee() { Firstname = txtFirstName.Text, Lastname = txtLastName.Text, DepartmentKey = ddDeps.SelectedValue };

            if (ds == null)
            {
                ds = new DtyoDataSource();
            }
            ds.AddEmployee(newEntry);

            txtFirstName.Text = "";
            txtLastName.Text = "";
            
            EmployeeList.DataBind();
        }
        protected void EmpTimer_Tick(object sender, EventArgs e)
        {
            EmployeeList.DataBind();
        }
    }
}